package pers.lxl.structure.queue;

public class Main {
    public static void main(String[] args) {
        // 使用数组队列
        // ArrayQueue<Integer> queue = new ArrayQueue<>();

        // 使用循环队列
        LoopQueue<Integer> queue = new LoopQueue<>();

        for (int i = 0; i < 5; i++) {
            queue.enqueue(i);
            System.out.println(queue.toString());
        }

        System.out.println(queue.toString());
        System.out.println(queue.getSize());
        System.out.println(queue.getCapacity());
        System.out.println(queue.isEmpty());
        System.out.println(queue.dequeue());
        System.out.println(queue.getFront());
        System.out.println(queue.toString());


        int count = 200000;

        ArrayQueue<Integer> arrayQueue = new ArrayQueue<>();
        LoopQueue<Integer> loopQueue = new LoopQueue<>();

        // 费时 7.373912788 秒
        System.out.println(testQueueTime(arrayQueue, count));

        // 费时 0.036812726秒
        System.out.println(testQueueTime(loopQueue, count));

        //  速度相差200多倍
    }


    /**
     * 测试队列操作的时间
     *
     * @param q     队列
     * @param count 操作次数
     * @return 时间
     */
    public static double testQueueTime(Queue<Integer> q, int count) {
        long start = System.nanoTime();

        for (int i = 0; i < count; i++) {
            q.enqueue(1);
        }
        for (int i = 0; i < count; i++) {
            q.dequeue();
        }

        long end = System.nanoTime();
        return (end - start) / 1000000000.0;
    }
}
